//home模块的小仓库
//引入接口文件
import { reqCategoryList, reqBannerList, reqFloorList } from '@/api'
const state = {
    //三级菜单数据
    categoryList: [],
    //banner轮播图数据
    bannerList: [],
    //floor轮播图数据
    floorList: []
};
const actions = {
    //通过api里的接口函数调用，向服务器发请求，获取服务器的数据
    async categoryList({ commit }) {
        let res = await reqCategoryList();
        if (res.code == 200) {
            commit('CATEGORYLIST', res.data)
        }
    },
    async bannerList({ commit }) {
        let res = await reqBannerList();
        if (res.code == 200) {
            commit('BANNERLIST', res.data)
        }
        console.log('home/banner actions');
    },
    async floorList({ commit }) {
        let res = await reqFloorList();
        if (res.code == 200) {
            commit('FLOORLIST', res.data)
        }
        console.log('home/banner actions');
    },
};
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList;
    },
    BANNERLIST(state, bannerList) {
        console.log('home/banner mutaions');
        state.bannerList = bannerList;
    },
    FLOORLIST(state, floorList) {
        console.log('home/floor mutaions');
        state.floorList = floorList;
    }
};

const getters = {};

export default {
    state,
    mutations,
    actions,
    getters
}